<?php

namespace app\api\controller\supplier;

use app\api\base\RestfulBase;
use app\modules\supplier\logic\SupplierLogic;

Class Supplier extends RestfulBase
{
    protected $logic;

    protected function _initialize()
    {

        $this->logic = new SupplierLogic();

    }

    /**
     * 获取供应商信息
     * @return Response
     */
    public function read()
    {
        if ($this->request->isGet()){
            $id = !empty($this->getParams('supplier_id', '', 'trim,strip_tags'))?$this->getParams('supplier_id', '', 'trim,strip_tags'):$this->_account['supplier_id'];
            $data = $this->logic->get($id);
            if (is_array($data)) {
                return $this->apiSuccess($data);
            } else {
                return $this->apiError($this->logic->getError());
            }
        }else{
            return $this->apiError('无效请求');
        }

    }

    /**
     * 编辑供应商信息
     * @return Response
     */
    public function update(){
        if ($this->request->isPost()){
            $id = !empty($this->getParams('supplier_id','','trim,strip_tags'))?$this->getParams('supplier_id','','trim,strip_tags'):$this->_account['supplier_id'];
            $data['supplier_name'] = $this->getParams('supplier_name', '', 'trim,strip_tags');
            $data['charge'] = $this->getParams('charge', '', 'trim,strip_tags');
            $data['charge_phone'] = $this->getParams('charge_phone', '', 'trim,strip_tags');
            $data['business'] = $this->getParams('business', '', 'trim,strip_tags');
            $data['idcard'] = $this->getParams('idcard', '', 'trim,strip_tags');
            $data['idcard_zp'] = $this->getParams('idcard_zp', '', 'trim,strip_tags');
            $data['idcard_fp'] = $this->getParams('idcard_fp', '', 'trim,strip_tags');

            if ($this->logic->edit($id,$data)){
                return $this->apiSuccess();
            }else{
                return $this->apiError($this->logic->getError());
            }

        }else{
            return $this->apiError('无效请求');
        }
    }


}

